﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BostonAzureSite.ViewHelpers
{
    public class MicrodataMarkupBuilder : ISemanticMarkupBuilder
    {
        const string MicrodataMarkupTemplate =
            "<span class=\"dtstart\">" +
               "<time datetime=\"{0}\" class=\"value\">{1} </time>" +
            "</span>";

        /// <summary>
        /// Convert UTC date/time into semantic HTML markup for the provided LOCAL timezone 
        /// </summary>
        /// <param name="dateTimeUtc">Expecting date/time as UTC</param>
        /// <param name="targetTimeZone">Target time zone - dateTimeUtc is converted from UTC to this time zone</param>
        /// <returns>Semantic HTML snippet based on Microdata conventions</returns>
        public string GetSemanticMarkupForTimeZone(DateTime dateTimeUtc, TimeZoneInfo targetTimeZone)
        {
            DateTime localTime = TimeZoneTranslator.GetLocalTimeFromUtcTime(dateTimeUtc, targetTimeZone);
            var localTimeIso8601DateTimeString = String.Format("{0:o}", localTime);
            var localTimeEnglishDateTimeString = String.Format("{0:f}", localTime);

            var semanticHtml = String.Format(
                MicrodataMarkupTemplate,
                localTimeIso8601DateTimeString,
                localTimeEnglishDateTimeString);
            return semanticHtml;            
        }
    }
}